﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace daStaticAnalyser.Analysers
{
    using daStaticAnalyser;
    using daBase.Objects;
    using daBase.Analyser;
    using daSyntaxAnalyser;
    using daSyntaxAnalyser.SyntaxTree;

    [AnalyserDefaultSettings("Метрика граничных значений", "test", 0, "test")]
    class BorderValueAnalyzer : BaseStaticAnalyser
    {

        int VisitGraph(EG node)
        {
            int Sa = 0;
            if (node.Visit) return 0;
            if (node.Next.Count <= 1) Sa = 1;
            foreach (var elt in node.Next) Sa+=VisitGraph(elt);
            return Sa;
        }
        protected override void DoAnalyse(SyntaxTreeArgs e)
        {
            String MethodName = "";
            if (CheckMethod_GetName(e, out MethodName))
            {
                OuterMethodElement Method = e.Element as OuterMethodElement;
                ControlGraph CG = new ControlGraph();
                CG.Build(Method.Body.Statement);

                int So, Sa = 1, v;
                v = CG.Elements.Count;
                So = 1 - (1 - v) / Sa;
                AddMetric("Метрика граничных значений", So,
                    MethodName,
                    Method.StartInfo.File,
                    Method.StartInfo.Line);
            }
        }
    }   
}
